using LF.WebCore;
using LF.Common;
using Serilog;
using LF.Application.Converts;

var builder = WebApplication.CreateBuilder(new WebApplicationOptions { ContentRootPath = AppConfig.BasePath });

#region appsettings
var file = "Config/app.json".ToPath();
if (File.Exists(file))
{
    builder.Configuration.AddJsonFile(file, true, true);
}
file = $"Config/app.{builder.Environment.EnvironmentName}.json".ToPath();
if (File.Exists(file))
{
    builder.Configuration.AddJsonFile(file, true, true);
}
#endregion

builder.Host.UseSerilog();
//abp使用autofac注入
builder.Host.UseAutofac();
//自定义服务端口
builder.WebHost.UseUrls(builder.Configuration["url"]!.Split(","));
//abp注入
builder.Services.AddApplication<AppModule>();
builder.Services.AddControllers().AddJsonOptions((options) => {
    options.JsonSerializerOptions.Converters.Add(new DateOnlyJsonConverter());
    options.JsonSerializerOptions.Converters.Add(new NullableDateOnlyJsonConverter());
});

builder.Services.AddHttpContextAccessor();

var app = builder.Build();
//abp initalize
app.InitializeApplication();

#if DEBUG
app.Map("/",() => Results.Redirect("/apis/index.html"));
#endif

app.Run();